package org.example.musicserver.controller;

import jakarta.annotation.Resource;
import org.example.musicserver.Request.UserRequest;
import org.example.musicserver.common.Result;
import org.example.musicserver.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
//
    @PostMapping("/login")
    public Result loginController(@RequestParam String name, @RequestParam String password){
        return userService.loginCheck(name,password);
    }
    @GetMapping("/all")
    public Result getAllUser(@RequestParam(required = false) String query){
        return userService.getAllUser(query);
    }
    //根据用户id获取一个用户的详细信息
    @GetMapping("/one")
    public Result getUserMsg(Integer id){
        return userService.getUserMsg(id);
    }
    @PutMapping("/update")
    public Result updateUserMsg(@RequestBody UserRequest updateRequest) {
        return userService.updateUserMsg(updateRequest);
    }

    // 根据用户id删除用户
    @DeleteMapping("/deleteone")
    public Result deleteUser(@RequestParam Integer userId) {
        return userService.deleteUser(userId);
    }

    @DeleteMapping("/deleteall")
    public Result deleteUsers(@RequestParam List<Integer> userIds) {
        return userService.deleteUsers(userIds);
    }

    @PostMapping("/add")
    public Result addUser(@RequestBody UserRequest registryRequest) {
        return userService.addUser(registryRequest);
    }

    @GetMapping("/register")
    public Result registerController(@RequestParam String name,@RequestParam String password){
        return userService.registerService(name,password);

    }
}
